﻿using ITXHWEB.Models;
using ReflectionStudio.Core.Events;
using System;
using System.Data;
using System.Web.Mvc;
using WPFExcelReport;
using WPFExcelReport.Helpers;
using ITXHWEB.Infrastructure;
using System.Collections;
using System.Collections.Generic;
namespace ITXHWEB.Controllers
{
    public partial class VVTLIEFController : ITXController
    { 
        public ActionResult SVVLIEF(string returnUrl)
        {
            ModelState.Clear();
            ViewBag.ReturnUrl = returnUrl; 
            return PartialView(MABF.CVVT);
        }
        [HttpPost]
        [AllowAnonymous]
        [ValidateAntiForgeryToken]
        public ActionResult SVVLIEF(VVTLIEFModel model, string returnUrl)
        {
            try
            {
                ModelState.Clear();
                LIEFSCH = model.LIEFSCH.Trim();
                MABF.CVVT.LIEFSCH = LIEFSCH; 
                VVLOAD(model); 
            }
            catch (Exception ex)
            {
                VKPAUF = ex.Message;
                Tracer.Error(ex.StackTrace, ex);
            }
            return RedirectToAction(MAPP, MAPP);
            //return RedirectToAction("ITXWB06", "ITXWB06", new { TempData = TempData });
            //return View(model);
        } 
        public void VVLOAD(VVTLIEFModel model)
        { 
            if (MABF.CVVT.LIEFSCH.Trim().Length < 5)
            {
                MABF.IsVVTReady = false;
                return; 
            } 
            PM["AUFTYP"] = "K"; 
            PM["LIEFSCH"] = LIEFSCH.Trim().PadRight(8); 
            DataSet SResult = VHP.VVT.VVCHK(PM);
            MABF.VVTS = new List<VVTLIEFModel>(); 
            foreach (DataRow row in SResult.Tables[0].Rows)
            {
                VVTLIEFModel m = new VVTLIEFModel();
                m.LIEFSCH = row["VVTLIEFSCH"].ToString();
                m.AUFTYP = row["VVTAUFTYP"].ToString();
                m.KRS = row["VVTAUFKRS"].ToString();
                m.LFD = row["VVTAUFLFD"].ToString();
                m.POS = row["VVTAUFPOS"].ToString();
                m.VKPAUF = row["VVTAUFKRS"].ToString() + row["VVTAUFLFD"].ToString() + row["VVTAUFPOS"].ToString();
                m.VFART = row["VVTART"].ToString() + row["VVTFARBE"].ToString();
                m.WAKZ = row["VVTWAKZ"].ToString();
                m.ART = row["VVTART"].ToString();
                m.VAR = row["VVTVAR"].ToString();
                m.FARBE = row["VVTFARBE"].ToString();
                MABF.VVTS.Add(m);
                MABF.IsVVTReady = true;
            }
        }
    }
}
